﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Convert
/// </summary>
public class ConvertDateType
{
    public ConvertDateType()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static int IntParse(string obj)
    {
        int result = 0;
        try
        {
            result = int.Parse(obj.Trim().Replace(",",""));
        }
        catch
        {
            result = 0;
        }

        return result;
    }
    
    public static string DateTryFormat(object d)
    {
       
        if (d == null || String.IsNullOrEmpty(d.ToString()))
        {
            return "";
        }
        else
        {
            try
            {
                if (Convert.ToDateTime(d) == DateTime.MinValue)
                {
                    return "";
                }
                else if (Convert.ToDateTime(d).ToString("yyyy-MM-dd")=="1900-01-01")
                {
                    return "";
                }
                else if (Convert.ToDateTime(d).ToString("yyyy-MM-dd") == "2999-12-31")
                {
                    return "";
                }
                else
                {
                    return Convert.ToDateTime(d).ToString("yyyy-MM-dd");
                }

            }
            catch (Exception ex)
            {
                return "";
            }

        }
    }

    public static string DateTimeTryFormat(object d)
    {
        if (d == null || String.IsNullOrEmpty(d.ToString()))
        {
            return "";
        }
        else
        {
            try
            {
                if (Convert.ToDateTime(d) == DateTime.MinValue)
                {
                    return "";
                }
                else if (Convert.ToDateTime(d).ToString("yyyy-MM-dd") == "1900-01-01")
                {
                    return "";
                }
                else
                {
                    return Convert.ToDateTime(d).ToString("yyyy-MM-dd HH:mm");
                }

            }
            catch (Exception ex)
            {
                return "";
            }

        }
    }

    public static float FloatTryFormat(string str)
    {
        float result = 0;
        try
        {
            result = float.Parse(str.Trim());
        }
        catch
        {
            result = 0;
        }

        return result;
    }
}